/**
 * Created by robin on 2016/11/18.
 * 资源整合
 */
simple = {
    /**列表页数据加载*/
    list:function(obj){
        if(obj.pageNum != '' && obj.pageNum != null)$("#pageNum").val(obj.pageNum);
        simple.request({url:obj.listUrl,type:"GET",data:$("#search").serialize(),success:function(data){$("#dataList").html(data);}});
    },
    /**分页插件加载*/
    page:function(obj){
        simple.pageSize();laypage({cont: $('#layPage'), pages: obj.pages, skip: true, skin: 'molv', curr:obj.curr, groups: 3,
            jump: function(e, first){if(!first){simple.list({pageNum:e.curr,listUrl:obj.listUrl});}}
        });
    },
    /**没有显示多少条数据插件*/
    pageSize:function(){
        var pageSize = $("#pageSize").val();var pageSizes = [5,10,15,20,25,30];var str ='';
        for(var i = 0;i<pageSizes.length;i++){
            if(pageSizes[i] == pageSize)str += '<option value="'+pageSizes[i]+'" selected>'+pageSizes[i]+'</option>';else str += '<option value="'+pageSizes[i]+'">'+pageSizes[i]+'</option>';
        }$("#sizeShow").html(str);
    },
    /**改变下拉框值后加载数据*/
    changeSize:function(url){
        $("#pageSize").val($("#sizeShow").val());simple.list({pageNum:1,listUrl:url});
    },
    /**删除修改状态抽象*/
    stateAndDel:function(obj){
        layer.confirm(obj.title, {btn: ['确定','取消'], icon:3}, function(index){layer.close(index);
            simple.request({url:obj.url,type:"POST",data:obj.data,success:function(data){
                if(data==1) simple.list({pageNum:1,listUrl:obj.listUrl});
            }});
        });
    },
    /**删除Data*/
    delData:function(obj){obj.title = "温馨提示:您确定删除此条数据";simple.stateAndDel(obj);},
    /**修改状态*/
    stateData:function(obj){obj.title = "温馨提示:您确定修改此条数据状态";simple.stateAndDel(obj);},
    /**加载层*/
    loading:function(){return layer.load(2,{shade: [0.2, '#393D49']});},
    /**输入框只能输入数字*/
    clearNoNum:function(obj){
        obj.value = obj.value.replace(/[^\d.]/g,"");obj.value = obj.value.replace(/^\./g,"");
        obj.value = obj.value.replace(/\.{2,}/g,".");
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
    },
    /**请求处理*/
    request:function(obj){
        var index = simple.loading();if(undefined == obj.alertError) obj.alertError = true;
        $.ajax({url:obj.url,type:obj.type,data:obj.data,success:function(data){
            var str = data.toString();if(str.indexOf("thisIsLoginPage") != -1){window.location.href="/manage/login";}layer.close(index);obj.success(data);
        },error:function(resp, textStatus, errorThrown){layer.close(index);if(obj.alertError){layer.msg(resp.responseText);}}});
    },
    /**layer弹层数据处理*/
    layerData:function(obj){
        simple.request({url:obj.openUrl,type:"GET",data:obj.openData,success:function(html){
            layer.open({
                type: 1, title:obj.openTitle,scrollbar: false,content: html, maxmin:false, area: [obj.width, obj.height], btn: ["确定","取消"],
                zIndex:2000,yes: function(index, layero){
                    var data = obj.returnData();if(data == null) data = $("#form").serialize();if(data == false) return "";
                    simple.request({url:obj.ajaxUrl,type:"POST",data:data,success:function(data){
                        if(data == 1){layer.close(index);if(obj.listUrl.length > 0)simple.list({pageNum:1,listUrl:obj.listUrl});}obj.success(data);
                    }});
                }
            });
        }});
    },
    /**layer弹层显示数据*/
    layerInfo:function(obj){
        simple.request({url:obj.openUrl,type:"GET",data:obj.openData,success:function(html){
            layer.open({type: 1, title:obj.openTitle,scrollbar:false,content: html,maxmin:false, area: [obj.width, obj.height],shadeClose: true});
        }});
    },
    /**加载文件上传插件*/
    upload:function(obj){
        if(obj.fileId == '' || obj.fileId == null)obj.fileId = '#file';
        var  html = '<div class="form-group" style="width: 650px;margin-left: 20px;margin-top: 5px;">';
        if(obj.type == 1)html += '<input id="file-5" type="file" class="file"';
        else if(obj.type == 2)html += '<input id="file-5" class="file" type="file" name="file" multiple data-preview-file-type="any" ';
        html += 'data-upload-url="'+obj.uploadUrl+'"/></div>';
        layer.open({type: 1, title:obj.openTitle,scrollbar:false, content: html, maxmin:false,
            area: [obj.width, obj.height],success: function(index, layero){
                $("#file-5").fileinput({}).on("fileuploaded",function(event, data){
                    if(obj.type == 1)$(obj.fileId).val(data.response.data.id); else if(obj.type == 2){var fileId = $(obj.fileId).val();
                        if(fileId.length > 0 ){fileId += ','+data.response.data.id;$(obj.fileId).val(fileId);
                        }else{$(obj.fileId).val(data.response.data.id);}}if(data.response.status == 0)setTimeout(function(){layer.close(layero);},1000);
                });
            }
        });
    },
    /**单文件上传*/
    oneUpload:function(fileId){simple.upload({type:1,uploadUrl:'common/file/upload',openTitle:'单文件上传',width:'720px',height:'400px',fileId:fileId});},
    /**多文件上传*/
    moreUpload:function(fileId){simple.upload({type:2,uploadUrl:'sys/file/upload',openTitle:'多文件上传',width:'720px',height:'400px',fileId:fileId});},
    /**js提交文件数据实现上传*/
    fileData:function(obj){
        var index = simple.loading();$.ajax({
            url: obj.url, type: "POST",dataType : "json", xhr: function() {return $.ajaxSettings.xhr();},
            success: function(data){obj.success(data);}, data: obj.data, cache: false, contentType: false, processData: false,
            error:function(resp, textStatus, errorThrown){layer.msg(resp.responseText);}
        });layer.close(index);
    },
    /**获取浏览器地址栏URL信息*/
    getUrl:function(){return window.location.search;},
    /**获取浏览器地址栏URL信息中的参数*/
    getUrlData:function(){
        var url = simple.getUrl().substr(1).split("&");var str = '{';
        for(var i = 0;i<url.length;i++){var urlStr = url[i];str += '"'+urlStr.substr(0,urlStr.indexOf("="))+'":"'+urlStr.substr(urlStr.indexOf("=")+1)+'"';if(i < url.length - 1) str += ","
        }str += '}';var obj = $.parseJSON(str);return obj;
    },
    /**平滑滚动到锚点*/
    goTarget:function(target) {
        $('html').animate({scrollTop: $(target).offset().top}, 800, 'linear');
    }
};
function loadPage(){window.location.reload();}
menu=[
    {code:"aboutUs",name:"关于我们",child:[
        /**{code:"aboutCompany",name:"公司介绍",title:"简介"},{code:"aboutTeam",name:"精英团队",title:"团队名称"},**/
        {code:"aboutNews",name:"新闻动态",title:"新闻标题",isTime:true},{code:"aboutCulture",name:"企业文化",title:"企业文化标题",isImg:true,isTime:true},
        {code:"aboutCare",name:"领导关怀",title:"标题",isImg:true,isTime:true},{code:"aboutWelfare",name:"社会公益",title:"公益标题",isImg:true,isTime:true}]
    },
    {code:"proSer",name:"产品与服务",child:[{code:"proPlan",name:"行业产品及解决方案",title:"系统名称",isCate:true,isTime:true,
    child:[{code:"proPlan_gov",name:"政府应用"},{code:"proPlan_com",name:"企业应用"},{code:"proPlan_ser",name:"定制服务"}]},{code:"proIPSer",name:"知识产权与技术咨询服务",title:"服务标题",isTime:true}]},
    {code:"personnel",name:"慧知人才",child:[{code:"perRecruit",name:"招贤纳士",title:"职位名称",isTime:true},{code:"perExpert",name:"企业专家库",title:"专家姓名",isImg:true}]}
];
banner=[{code:"home",name:"首页轮播",size:"1920X458"},{code:"aboutUs",name:"关于我们",size:"1920X350"},{code:"proSer",name:"产品与服务",size:"1920X350"},{code:"personnel",name:"慧知人才",size:"1920X350"},{code:"contact",name:"联系我们",size:"1920X350"},{code:"partner",name:"合作伙伴",size:"230X110"}];
